package com.easylinkin.linkappapi.common.utils;

/**
 * <p></p>
 *
 * @author TongJie
 * @since 2020/4/18 22:09
 */

import com.alibaba.druid.filter.config.ConfigTools;
import com.alibaba.druid.util.DruidPasswordCallback;
import org.junit.Test;

/**
 * 数据库配置加密使用 修改password字符串为对应的密码输出 copy对应的publicKey放在yml中对应useName中的publicKey和key copy对应的password到对应的password
 *
 * @author matthew
 */
public class EncryptPwdUtilTest extends DruidPasswordCallback {

    @Test
    public void encryptPwdUtil() {
        try {
            String password = "ws6umbXqO2_KYghoD4GInbXNoyOIfPqd";
            String[] arr = ConfigTools.genKeyPair(512);

            System.out.println("publicKey:" + arr[1]);
            System.out.println("password:" + ConfigTools.encrypt(arr[0], password));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Test
    public void encrypt() {
        String publickey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALNUDhL3p7INgkL1kxTUwI/npf2oGHTwYv4q+UgbA0WFWMbau001oUSjBO9FWMnHqVXSUPXg0JMG3b5mtkKitsUCAwEAAQ==";
        String privateKey = "rDSUoon268EceLRuNx10NShF2xBEl/+plplrXbhl7gEr4tydIcYUITnJ8C9T5vZw0G4fOU9BklKmxD82R25HhA==";
//        String password = "XmnTPIq6I6ENaAfAv3vQ/hP2oCy4cQBM16Llko0yAimriGAc0I7BIWUQ+YNqUyPD+RyoLgk/eYq+jA/fKMQ4Gg==";
        try {
            String dbpassword = ConfigTools.decrypt(publickey, privateKey);
            System.out.println("dbpassword=" + dbpassword);
//            String encryptPwd = ConfigTools.encrypt(privateKey, "123456");
//            System.out.println("encryptPwd=" + encryptPwd);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
